//Parser object that contains all parser for all skins
//Parser = function Parser() {}; //No need to initialize

/**
 * @function namespace/signatrue - Component type : Control type : Parser.formskin : Parser.impl
 * conf - configuration properties for layout
 * prop - properties
 * parentconf - parent element conf
 * parentprop - parent element prop
 * Parser[0:1:2:3:4]
 * 0-控件类型
 * 1-控件类型名称
 * 2-主题名称
 * 3-解析器名称
 * 4-解析类型
 */
Parser["control:datepickeropt:bootstrap-blue:Json2htmlParser:html"] = function(confs) {
	var s = "";
	for (var c in confs) {
		var conf = confs[c];
		var prop = conf.id ? Parser.props[conf.id] : {};
		//Parser.log("===="+JSON.stringify(prop));
		Parser.log(JSON.stringify(conf));
		Parser.log(JSON.stringify(prop));
		var required = Parser.parseValidator(conf.id);
		Parser.parseI18ntip(conf.id);
		var data = {};
		data.id = conf.id;
		data['i18nname-'+Parser.lang] = prop["i18nname-"+Parser.lang];
		data.databinding = prop.databinding;
		data.style = Parser.cssDisplay(prop.display)+(prop.style?prop.style:"")+(prop.margintop?"margin-top:"+prop.margintop:"");
		//Parser.log("data=============="+JSON.stringify(data));
		var transform = {"tag":"i"};
		var fmdcols = parseInt(conf.fmdcols);
		//Parser.log("fmdcols==================="+fmdcols);
		var cols = [1,fmdcols-1];
		if(fmdcols>3) {
			cols = [2,fmdcols-2];
		}
		var hourOption = '';
		for(var i = 0;i<24;i++){
			if(i<10){
				hourOption += '<option value="0'+i+'">0'+i+'</option>';
			}else{
				hourOption += '<option value="'+i+'">'+i+'</option>';
			}
		}
		Parser.log("hourOption=============="+hourOption);
		var minOption = '';
		for(var i =0;i<60;i+=5){
			if(i<10){
				minOption += '<option value="0'+i+'">0'+i+'</option>';
			}else{
				minOption += '<option value="'+i+'">'+i+'</option>';
			}
		}
		Parser.log("Parser.cssDisplay=="+Parser.cssDisplay(prop.display));
		var dateDivHtml= '<div '+(data.style ? ' style="'+data.style+'"' : '')+' class="input-append date text-nowrap '+(prop.disabled=='1' ? '' : 'form_date')+' '+(prop.classNames ? prop.classNames : '')+'">';
		
		var inputClass ="form-control";
		var spanHtml ='<span class="add-on iconon" style="'+Parser.cssDisplay(prop.display)+'margin-right:43%;top:0px;"><i class="icon-remove"></i></span>'+
        '<span class="add-on add-remove iconremove" style="'+Parser.cssDisplay(prop.display)+'margin-right:43%;top:0px;border-radius:0 4px 4px 0;"><i class="icon-calendar"></i></span>';
		
		transform.html = '<span class="col-md-'+cols[0]+'"'
						+ (data.style ? ' style="'+data.style+'"' : '')
						+ '><p'
						+ (prop["i18ntip-"+Parser.lang] ? (' title="'+prop["i18ntip-"+Parser.lang]+'"') : '')
						+ (prop.hideLabel=='1' ? ' style="display:none;"' : '')
						+ '>'
						+ (required ? '<span class="xh">*</span>' : '')
						+ '${i18nname-'+Parser.lang+'}'
						+ (prop["i18ntip-"+Parser.lang] ? ('&nbsp;<i class="glyphicon glyphicon-question-sign"></i>') : '')
						+ '</p></span>'
						+ '<span class="item cellborder col-md-'+cols[1]+'"'
						+ (data.style ? ' style="'+data.style+'white-space: nowrap;"' : '')
						+ '>'
						+ dateDivHtml
						+ '<input type="text" readonly="readonly"'
						+ (' class="'+inputClass+'"')
						+ ' style="width:50%;"'
//						+ ' databinding="${databinding}.substr(0,10)"'
						+ ' maxlength="${maxlength}"' 
						+ ' value="{{b.'+prop.databinding+' ? b.'+prop.databinding+'.substr(0,10) : \'\'}}"'
						+ ' id="${id}-1"'
						+ ' onchange="fmdf.onDatepickeroptChange(event,\'${id}-1\')"'
						+ ' desc="${i18nname-'+Parser.lang+'}"'
						+ ' name="${id}-1"'
						+ ' ng-init="b.'+prop.databinding+'mova.date=b.'+prop.databinding+'.substr(0,10)"'
						+ ' ng-model="b.'+prop.databinding+'mova.date"'//+ ' ng-model="b.'+prop.databinding+'"'
						+ ' placeholder="'+(prop.placeholder?prop.placeholder:'')+'"'
						+ '/>'
						+ spanHtml
						+ '<select ng-model="b.'+prop.databinding+'mova.hour"'// ng-options="x for x in datepicker_hours" 
						+ (' class="'+inputClass+'"')
						+ ' id="${id}-2"'
						+ (prop.disabled=='1' ? ' disabled="disabled"' : '')
						+ ' value="{{b.'+prop.databinding+' ? b.'+prop.databinding+'.substr(11,2) : \'\'}}"'
						+ ' ng-init="b.'+prop.databinding+'mova.hour = b.'+prop.databinding+'.substr(11,2)"'
//						+ ' ng-init="b.'+prop.databinding+'mova.hour = \'10\'"'
						+ 'style="width:20%;margin-left:7%;padding:1px;"'
						+ ' onchange="fmdf.onDatepickeroptChange(event,\'${id}-2\')">'+hourOption+'</select>'
						+ '<select ng-model="b.'+prop.databinding+'mova.min"'//ng-options="x for x in datepicker_minutes" 
						+ (' class="'+inputClass+'"')
						+ ' id="${id}-3"'
						+ (prop.disabled=='1' ? ' disabled="disabled"' : '')
						+ ' value="{{b.'+prop.databinding+' ? b.'+prop.databinding+'.substr(14,2) : \'\'}}"'
						+ ' ng-init="b.'+prop.databinding+'mova.min = b.'+prop.databinding+'.substr(14,2)"'
						+ 'style="width:20%;margin-left:2%;padding:1px;"'
						+ ' onchange="fmdf.onDatepickeroptChange(event,\'${id}-3\')">'+minOption+'</select>'
						+ '<input type="text" style="display:none;"'
						+ ' id="${id}"'
						//+ ' value="{{b.'+prop.databinding+'mova.hour.value}}"'//??value在此无用 {{b.'+prop.databinding+'1.date}}{{b.'+prop.databinding+'1.hour.value}}{{b.'+prop.databinding+'1.min.value}}
						+ ' desc="'+ prop["i18nname-" + Parser.lang] +'"'
						+ ' name="${id}"'
//						+ ' onchange="fmdf.onDatepickeroptChange(\'${id}\')"'
						+ ' ng-model="b.'+prop.databinding+'"'
						+ ' databinding="${databinding}"'
						+ '/>'
						+ '</div></span>';
		
		var wrapper = json2html.transform(data, transform);
		s += wrapper.substr(0, wrapper.length-4).substr(3);
	}
	return s;
};

Parser["control:datepickeropt:default:Json2htmlParser:html"] = function(confs) {
	var s = "";
	for (var c in confs) {
		var conf = confs[c];
		var prop = conf.id ? Parser.props[conf.id] : {};
		Parser.log("zzzz===="+JSON.stringify(prop));
		Parser.log(JSON.stringify(conf));
		Parser.log(JSON.stringify(prop));
		var required = Parser.parseValidator(conf.id);
		Parser.parseI18ntip(conf.id);
		var data = {};
		data.id = conf.id;
		data['i18nname-'+Parser.lang] = prop["i18nname-"+Parser.lang];
		data.databinding = prop.databinding;
		data.style = Parser.cssDisplay(prop.display)+(prop.style?prop.style:"")+(prop.margintop?"margin-top:"+prop.margintop:"");
		Parser.log("data=============="+JSON.stringify(data));
		var transform = {"tag":"i"};
		var fmdcols = parseInt(conf.fmdcols);
		Parser.log("fmdcols==================="+fmdcols);
		var cols = [1,fmdcols-1];
		if(fmdcols>3) {
			cols = [2,fmdcols-2];
		}
		var hourOption = '';
		for(var i = 0;i<24;i++){
			if(i<10){
				hourOption += '<option value="0'+i+'">0'+i+'</option>';
			}else{
				hourOption += '<option value="'+i+'">'+i+'</option>';
			}
		}
		Parser.log("hourOption=============="+hourOption);
		var minOption = '';
		for(var i =0;i<60;i+=5){
			if(i<10){
				minOption += '<option value="0'+i+'">0'+i+'</option>';
			}else{
				minOption += '<option value="'+i+'">'+i+'</option>';
			}
		}
		
		var dateDivHtml= '<div '+(data.style ? ' style="'+data.style+'"' : '')+' class="input-append date text-nowrap '+(prop.disabled=='1' ? '' : 'form_date')+' '+(prop.classNames ? prop.classNames : '')+'">';
		var inputClass ="form-control";
		var spanHtml ='<span class="add-on iconon" style="'+Parser.cssDisplay(prop.display)+'margin-right:43%;top:8px;"><i class="icon-remove"></i></span>'+
        '<span class="add-on add-remove iconremove" style="'+Parser.cssDisplay(prop.display)+'margin-right:43%;top:8px;border-radius:0 4px 4px 0;"><i class="icon-calendar"></i></span>';
		
		transform.html = '<span class="label col-md-'+cols[0]+'"'
						+ (data.style ? ' style="'+data.style+'"' : '')
						+ '><p'
						+ (prop["i18ntip-"+Parser.lang] ? (' title="'+prop["i18ntip-"+Parser.lang]+'"') : '')
						+ (prop.hideLabel=='1' ? ' style="display:none;"' : '')
						+ '>'
						+ (required ? '<span class="xh">*</span>' : '')
						+ '${i18nname-'+Parser.lang+'}'
						+ (prop["i18ntip-"+Parser.lang] ? ('&nbsp;<i class="glyphicon glyphicon-question-sign"></i>') : '')
						+ '</p></span>'
						+ '<span class="item cellborder col-md-'+cols[1]+'"'
						+ (data.style ? ' style="'+data.style+'white-space: nowrap;"' : '')
						+ '>'
						+ dateDivHtml
						+ '<input type="text" readonly="readonly"'
						+ (' class="'+inputClass+'"')
						+ ' style="width:50%;"'
						+ ' databinding="{{${databinding}.substr(0,10)}}"'
						+ ' maxlength="${maxlength}"' 
//						+ ' value="{{b.'+prop.databinding+' ? b.'+prop.databinding+'.substr(0,10) : \'\'}}"'
						+ ' id="${id}-1"'
						+ ' onchange="fmdf.onDatepickeroptChange(event,\'${id}-1\')"'
						+ ' desc="${i18nname-'+Parser.lang+'}"'
						+ ' name="${id}-1"'
						+ ' ng-init="b.'+prop.databinding+'mova.date=b.'+prop.databinding+'.substr(0,10)"'
						+ ' ng-model="b.'+prop.databinding+'mova.date"'//+ ' ng-model="b.'+prop.databinding+'"'
						+ ' placeholder="'+(prop.placeholder?prop.placeholder:'')+'"'
						+ '/>'
						+ spanHtml
						+ '<select ng-model="b.'+prop.databinding+'mova.hour" '// ng-options="x for x in datepicker_hours" 
						+ (' class="'+inputClass+'"')
						+ ' id="${id}-2"'
						+ (prop.disabled=='1' ? ' disabled="disabled"' : '')
						+ ' value="{{b.'+prop.databinding+' ? b.'+prop.databinding+'.substr(11,2) : \'\'}}"'
						+ ' ng-init="b.'+prop.databinding+'mova.hour = b.'+prop.databinding+'.substr(11,2)"'
//						+ ' ng-init="b.'+prop.databinding+'mova.hour = \'10\'"'
						+ 'style="width:20%;margin-left:7%;padding:1px;"'
						+ ' onchange="fmdf.onDatepickeroptChange(event,\'${id}-2\')">'+hourOption+'</select>'//'+hourOption+'
						+ '<select ng-model="b.'+prop.databinding+'mova.min" '// ng-options="x for x in datepicker_minutes"
						+ (' class="'+inputClass+'"')
						+ ' id="${id}-3"'
						+ (prop.disabled=='1' ? ' disabled="disabled"' : '')
						+ ' value="{{b.'+prop.databinding+' ? b.'+prop.databinding+'.substr(14,2) : \'\'}}"'
						+ ' ng-init="b.'+prop.databinding+'mova.min = b.'+prop.databinding+'.substr(14,2)"'
						+ 'style="width:20%;margin-left:2%;padding:1px;"'
						+ ' onchange="fmdf.onDatepickeroptChange(event,\'${id}-3\')">'+minOption+'</select>'//'+minOption+'
						+ '<input type="text" style="display:none;"'
						+ ' id="${id}"'
						//+ ' value="{{b.'+prop.databinding+'mova.hour.value}}"'//??value在此无用 {{b.'+prop.databinding+'1.date}}{{b.'+prop.databinding+'1.hour.value}}{{b.'+prop.databinding+'1.min.value}}
						+ ' desc="'+ prop["i18nname-" + Parser.lang] +'"'
						+ ' name="${id}"'
//						+ ' onchange="fmdf.onDatepickeroptChange(\'${id}\')"'
						+ ' ng-model="b.'+prop.databinding+'"'
						+ ' databinding="${databinding}"'
						+ '/>'
						+ '</div></span>';
		
		var wrapper = json2html.transform(data, transform);
		s += wrapper.substr(0, wrapper.length-4).substr(3);
	}
	return s;
};



